package org.restlesscode.javersion;

import java.io.Serializable;

/**
 * Defines the content of an SVN property. SVN properties can be
 * String or byte arrays (serializable objects).
 */
public class SvnPropertyObject {

    /**
     * Properties can be saved as either Strings or Objects (Binary).
     */
    public enum PropertyType {
        STRING,
        OBJECT
    }

    protected Serializable value;
    protected PropertyType propertyType;

    /**
     * Create a property object from a serializable value given a
     * property type.
     * @param value Value to serialize.
     * @param propertyType String or Object
     */
    public SvnPropertyObject(Serializable value, PropertyType propertyType) {
        this.value = value;
        this.propertyType = propertyType;
    }

    /**
     * Returns the value of the property.
     * @return
     */
    public Serializable getValue() {
        return this.value;
    }

    /**
     * Returns the type of the property: String or Object
     * @return
     */
    public PropertyType getPropertyType() {
        return this.propertyType;
    }

    /**
     * If the type is a String, return the value cast to a String.
     * If the type is an Object, return its toString().
     * @return
     */
    public String getValueAsString() {
        switch(propertyType) {
            case STRING:
                return (String) value;
            default:
                return value.toString();
        }
    }

}
